package com.nio.c1_NettyTest;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @version No one is coming, unless you change yourself!!!
 * @author： pang-yun
 * @date： 2021-05-27 20:10
 */

@Slf4j
public class MyByteBufferTest {

    public static void main(String[] args) {
        try (FileChannel fileChannel = new FileInputStream("data.txt").getChannel()) {

            ByteBuffer byteBuffer = ByteBuffer.allocate(10);

            while (true){
                int readLength = fileChannel.read(byteBuffer);
                log.debug("************readLength==={}",readLength);
                if (readLength==-1){break;}

                byteBuffer.flip();

                while (byteBuffer.hasRemaining()) {
                    byte b = byteBuffer.get();
                    log.debug("***********输出字符是 {} ************",(char)b);

                }
                byteBuffer.clear();
            }



        } catch (IOException e) {
        }
    }
}
